package net.aetherial.context.grounding.annotators;

import java.util.*;

import net.aetherial.context.grounding.estimators.*;

/**
 * Generates an annotated layer by stripping out all non-alphanumeric characters.
 */

public class PunctuationStrippingAnnotator extends Annotator 
{
	private static HashSet<String> valid;
	
	static
	{
		valid = new HashSet<String> ();
		
		String[] symbols = {	"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
								"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
								"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", " " };
		
		for (String symbol: symbols)
			valid.add (symbol);
	}
	
	/**
	 * @see net.aetherial.context.grounding.annotators.Annotator#annotate(java.lang.String, java.lang.String, double)
	 */
	
	public Map<String, Object> annotate (String sender, String contribution, double score)
	{
		Map<String, Object> layer = super.annotate (sender, contribution, score);
		
		layer.put (Estimator.CONTRIBUTION_KEY, this.annotate (contribution));
		
		return layer;
	}
	
	/**
	 * Generates an annotated version devoid of punctuation characters.
	 * 
	 * @param contribution		Original conversational unit.
	 * @return					Annotated version.
	 */
	
	public String annotate (String contribution) 
	{
		contribution = contribution.toLowerCase ();
		
		StringBuffer retValue = new StringBuffer ();
		
		for (int i = 0; i < contribution.length (); i++)
		{
			char c = contribution.charAt (i);
			
			if (valid.contains ("" + c))
				retValue.append (c);
		}
		
		return retValue.toString ();
	}

	/**
	 * Returns "Punctuation Free Layer".
	 * 
	 * @see net.aetherial.context.grounding.annotators.Annotator#getLayerName()
	 */
	
	public String getLayerName () 
	{
		return "Punctuation Free Layer";
	}
}
